#include "fileprogressbar.h"
#include "ui_fileprogressbar.h"
#include<QDebug>
#include<QIcon>

FileProgressBar::FileProgressBar(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FileProgressBar)
{
    ui->setupUi(this);
    setFixedSize(621,157);
    closeBtnEnabled=false;
    setWindowModality(Qt::ApplicationModal);
    setWindowIcon(QIcon(":/img/application.png"));
}

FileProgressBar::~FileProgressBar()
{
    delete ui;
}

void FileProgressBar::setProgressBar(const QString &text)
{
    setWindowTitle(text);
    closeBtnEnabled=false;
    ui->tipLabel->setText(text+":");
    ui->progressBar->setValue(0);
}

void FileProgressBar::setProgressValue(int value)
{
    ui->progressBar->setValue(value);
}

bool FileProgressBar::getCloseBtnEnabled() const
{
    return closeBtnEnabled;
}

void FileProgressBar::setCloseBtnEnabled(bool newCloseBtnEnabled)
{
    closeBtnEnabled = newCloseBtnEnabled;
}

void FileProgressBar::closeEvent(QCloseEvent *event)
{
    if(closeBtnEnabled){
        event->accept();
    }else{
        emit showTip("进度条操作还未结束，无法关闭");
        event->ignore();  // 阻止窗口关闭
    }
}
